package cn.iocoder.yudao.module.tms.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 美线清关流程状态枚举
 *
 * @author 芋道源码
 */
@Getter
@AllArgsConstructor
public enum ClearanceStatusEnum {

    // 初始状态
    ISF_DECLARATION("ISF_DECLARATION", "ISF申报", null),
    DOCUMENT_PROCESSING("DOCUMENT_PROCESSING", "单证处理", ISF_DECLARATION),
    DOCUMENT_SUBMISSION("DOCUMENT_SUBMISSION", "资料提交", DOCUMENT_PROCESSING),
    CUSTOMS_FOLLOW_UP("CUSTOMS_FOLLOW_UP", "海关跟进", DOCUMENT_SUBMISSION),
    INSPECTION_INSTRUCTION("INSPECTION_INSTRUCTION", "查验指令", CUSTOMS_FOLLOW_UP),
    CONFIRM_INSPECTION_TYPE("CONFIRM_INSPECTION_TYPE", "确认查验类型", INSPECTION_INSTRUCTION),
    NORMAL("NORMAL", "正常", CONFIRM_INSPECTION_TYPE),
    ABNORMAL("ABNORMAL", "异常", CONFIRM_INSPECTION_TYPE),
    FEEDBACK_TO_CUSTOMER("FEEDBACK_TO_CUSTOMER", "反馈给客户", ABNORMAL),
    FOLLOW_UP_CONNECTION("FOLLOW_UP_CONNECTION", "跟进对接", ABNORMAL),
    TAX_CONFIRMATION("TAX_CONFIRMATION", "税金确认", NORMAL),
    PAYMENT("PAYMENT", "付款", TAX_CONFIRMATION),
    CLEARANCE_COMPLETED("CLEARANCE_COMPLETED", "清关完成", PAYMENT),
    CUSTOMS_RELEASE("CUSTOMS_RELEASE", "通关放行", CLEARANCE_COMPLETED),
    GOODS_PICKUP_COMPLETED("GOODS_PICKUP_COMPLETED", "提货完成", CUSTOMS_RELEASE),
    TRANSFER("TRANSFER", "转关", CLEARANCE_COMPLETED),
    RETURN("RETURN", "退运", CLEARANCE_COMPLETED),
    DESTROY("DESTROY", "销毁", CLEARANCE_COMPLETED);

    /**
     * 状态编码
     */
    private final String code;
    
    /**
     * 状态名称
     */
    private final String name;
    
    /**
     * 前置状态
     */
    private final ClearanceStatusEnum previousStatus;

    /**
     * 获取前置状态
     *
     * @return 前置状态
     */
    public ClearanceStatusEnum getPreviousStatus() {
        return previousStatus;
    }
    
    /**
     * 获取后置状态列表
     *
     * @return 后置状态列表
     */
    public List<ClearanceStatusEnum> getNextStatusList() {
        List<ClearanceStatusEnum> nextStatusList = new ArrayList<>();
        for (ClearanceStatusEnum status : values()) {
            if (status.getPreviousStatus() == this) {
                nextStatusList.add(status);
            }
        }
        return nextStatusList;
    }
    
    /**
     * 根据状态编码获取状态
     *
     * @param code 状态编码
     * @return 状态
     */
    public static ClearanceStatusEnum getByCode(String code) {
        for (ClearanceStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
}
